package m1.server;

import m1.server.composant.connectionmanager.ConnectionManager;
import m1.server.composant.database.DataBase;
import m2.Configuration;
import m2.attachement.AttachementRFPR;
import m2.attachement.AttachementRRPF;
import m2.binding.BindingF;
import m2.binding.BindingR;
import m2.binding.TypeBinding;
import m2.port.PortConfigFourni;
import m2.port.PortConfigRequis;
import m2.port.PortFourni;
import m2.port.PortRequis;
import m2.role.RoleFourni;
import m2.role.RoleRequis;
import m1.server.composant.securitymanager.SecurityManager;
import m1.server.connecteur.clearancerequest.*;
import m1.server.connecteur.securityquery.*;
import m1.server.connecteur.sqlquery.*;

public class ServeurConfig extends Configuration {

	/**
	 * Constructeur de la configuration Serveur
	 */
	public ServeurConfig() {
		super("ServerConfig");
		// Ajout des composant
		ConnectionManager connectionManager = new ConnectionManager(this);
		this.addComposant(connectionManager);
		DataBase dataBase = new DataBase(this);
		this.addComposant(dataBase);
		SecurityManager securityManager = new SecurityManager(this);
		this.addComposant(securityManager);
		// Ajout des connecteurs
		ClearanceRequest clearanceRequest = new ClearanceRequest();
		this.addConnecteur(clearanceRequest);
		SQLQuery sqlQuery = new SQLQuery();
		this.addConnecteur(sqlQuery);
		SecurityQuery securityQuery = new SecurityQuery();
		this.addConnecteur(securityQuery);

		// Ajout des attachements entre les composant ConnectionManager et le
		// connecteur SQLQuery.
		RoleFourni roleFourni = sqlQuery.getRoleFournisMap().get(
				"ConnectionManagerRF");
		PortRequis portRequis = connectionManager.getLesPortsRequis().get(
				"SendRequestIntP");
		AttachementRFPR attachementRFPR = new AttachementRFPR(
				"AttachementRFPR", portRequis, roleFourni);
		addAttachementRFPR(attachementRFPR);

		RoleRequis roleRequis = sqlQuery.getRoleRequisMap().get(
				"ConnectionManagerRR");
		PortFourni portFourni = connectionManager.getLesPortsFournis().get(
				"ReceiveRequestDBP");

		AttachementRRPF attachementRRPF = new AttachementRRPF(
				"AttachementRRPF", roleRequis, portFourni);
		addAttachementRRPF(attachementRRPF);
		// Ajout des attachements entre les connecteur SqlQuery et le composant
		// DataBase

		roleRequis = sqlQuery.getRoleRequisMap().get("DataBaseRR");
		portFourni = dataBase.getLesPortsFournis().get("SendRequestIntP");
		attachementRRPF = new AttachementRRPF("AttachementRRPF", roleRequis,
				portFourni);
		addAttachementRRPF(attachementRRPF);

		roleFourni = sqlQuery.getRoleFournisMap().get("DataBaseRF");
		portRequis = dataBase.getLesPortsRequis().get("ReceiveRequestIntP");

		addAttachementRFPR(new AttachementRFPR("AttachementRFPR", portRequis,
				roleFourni));

		// Ajout des attachement entre le connecteur SecurityQuery et le
		// composant SecurityManager
		portFourni = dataBase.getLesPortsFournis().get("SendAnswerSecurityP");
		roleRequis = securityQuery.getRoleRequisMap().get("DataBaseRR");
		addAttachementRRPF(new AttachementRRPF("AttachementRRPF", roleRequis,
				portFourni));

		portRequis = dataBase.getLesPortsRequis()
				.get("RecieveRequestSecurityP");
		roleFourni = securityQuery.getRoleFournisMap().get("DataBaseRF");
		addAttachementRFPR(new AttachementRFPR("AttachementRFPR", portRequis,
				roleFourni));

		// Ajout des attachement entre le composant SecurityManager et le
		// connecteur SecurityQuery
		roleFourni = securityQuery.getRoleFournisMap().get("SecurityManagerRF");
		portRequis = securityManager.getLesPortsRequis().get(
				"SendAnswerSecurityP");
		addAttachementRFPR(new AttachementRFPR("AttachementRFPR", portRequis,
				roleFourni));

		roleRequis = securityQuery.getRoleRequisMap().get("SecurityManagerRR");
		portFourni = securityManager.getLesPortsFournis().get(
				"ReceiveRequestSecurityP");

		addAttachementRRPF(new AttachementRRPF("AttachementRRPF", roleRequis,
				portFourni));

		// Ajout des attachement entre les connecteur ClearenceRequeste et les
		// composant SecurityManager

		portFourni = securityManager.getLesPortsFournis().get(
				"ReceiveSecurityAuthP");
		roleRequis = clearanceRequest.getRoleRequisMap().get(
				"SecurityManagerRR");
		addAttachementRRPF(new AttachementRRPF("AttachementRRPF", roleRequis,
				portFourni));

		portRequis = securityManager.getLesPortsRequis().get(
				"SendAnswerSecurityP");
		roleFourni = clearanceRequest.getRoleFournisMap().get(
				"SecurityManagerRF");
		addAttachementRFPR(new AttachementRFPR("AttachementRFPR", portRequis,
				roleFourni));

		// Ajout des attachements entre le composant Connection manager et le
		// connecteur Clearence Request

		portFourni = connectionManager.getLesPortsFournis().get(
				"SendSecurityAuthP");
		roleRequis = clearanceRequest.getRoleRequisMap().get(
				"ConnectionManagerRR");

		addAttachementRRPF(new AttachementRRPF("AttachementRRPF", roleRequis,
				portFourni));

		portRequis = connectionManager.getLesPortsRequis().get(
				"ReceiveSecurityAuthP");
		roleFourni = clearanceRequest.getRoleFournisMap().get(
				"ConnectionManagerRF");

		addAttachementRFPR(new AttachementRFPR("AttachementRFPR", portRequis,
				roleFourni));

		// Ajout des Bindings
		PortConfigFourni portConfigFourni = new PortConfigFourni(
				"ReceiveAnswerF");
		portConfigFourni.setConfig(this);
		PortConfigRequis portConfigRequis = new PortConfigRequis("SendRequestR");
		portConfigRequis.setConfig(this);
		this.addPortConfigF(portConfigFourni);
		this.addPortConfigR(portConfigRequis);
		addBindingF(new BindingF("BindinF", portConfigFourni, connectionManager
				.getLesPortsFournis().get("ExternalSocketFP"),TypeBinding.PortConf2PortComp));
		addBindingR(new BindingR("BindinR", portConfigRequis, connectionManager
				.getLesPortsRequis().get("ExternalSocketRP"),TypeBinding.PortConf2PortComp));

	}
}